package com.carey.yygh.hosp.util;

import com.carey.yygh.common.exception.YyghException;
import com.carey.yygh.common.helper.HttpRequestHelper;
import com.carey.yygh.common.result.ResultCodeEnum;
import com.carey.yygh.common.util.MD5;
import com.carey.yygh.hosp.service.HospitalSetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Component
public class signKeyUtil {
    @Autowired
    HospitalSetService hospitalSetService;

    public Map<String, Object> signkey(HttpServletRequest request){
        Map<String, String[]> parameterMap = request.getParameterMap();
        Map<String, Object> switchMap = HttpRequestHelper.switchMap(parameterMap);
        //判断signkey
        String  sign = (String) switchMap.get("sign");
        String hoscode = (String) switchMap.get("hoscode");
        String signkey = hospitalSetService.getSignKey(hoscode);
        String sign1 = MD5.encrypt(signkey);
        if (!sign.equals(sign1)){
            throw new YyghException(ResultCodeEnum.SIGN_ERROR);
        }
        return switchMap;
    }
}
